<?php
//Start session
	@session_start();
	if(isset($_GET['admin'])){
		$headers="../admin/index.php?update_course=success";
		$headerf="../admin/index.php?update_course=fail";
	}
	else{
		$headers="../courses.php?update=success";
		$headerf="../courses.php?update=fail";
	}
	
	//Include database connection details
	require_once('inc/config.inc');
//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	$query =  mysql_query("UPDATE courses SET course_title='".$_GET['cname']."', description='".$_GET['desc']."',category_id='".$_GET['course_cat']."',NumOfStudents='".$_GET['numStd']."',startdate='".$_GET['from']."',finishdate='".$_GET['to']."',address='".$_GET['address']."'
							WHERE id='".$_GET['course_id']."'");
	if($query){
		header("Location: ".$headers);
	}
	else{
		header("Location: ".$headerf);
	}

	?>